<template>
  <h1>El-作业1</h1>
  <el-form style="width: 500px;margin: 0 auto">
    <el-form-item label="姓名">
<el-input v-model="user.name" placeholder="请输入姓名" ></el-input>
    </el-form-item>
    <el-form-item label="工资">
      <el-input show-password v-model="user.salary" placeholder="请输入工资"></el-input>
    </el-form-item>
    <el-form-item label="岗位">
      <el-input v-model="user.job" placeholder="请输入岗位"></el-input>
    </el-form-item>
    <el-form-item>
      <el-button type="success" @click="insert()">点我提交</el-button>
    </el-form-item>
  </el-form>

  <el-table :data="userData" style="width: 50% ;margin: 0 auto" border="1px " >
<!--    <el-table-column prop="i" label="编号" type="index" width="180"/>
    <el-table-column prop="name" label="姓名" width="180"/>
    <el-table-column prop="salary" label="工资" width="180"/>
    <el-table-column prop="job" label="岗位"/>-->
    <el-table-column v-for="col in tableColumns" v-bind="col">
      
    </el-table-column>

    <el-table-column>
      <template #default="scope">
        <el-button type="danger" @click="del(scope.$index,scope.row)">buttonCont</el-button>
      </template>

    </el-table-column>

  </el-table>
</template>

<script setup>
import {ref} from "vue";
const del = (i,emp) =>{
  userData.value.splice(i,1);
}
const user = ref({
  name:'',
  salary:'',
  job:''
})
const tableColumns = ref([
  {
    type:'index',label:'编号',width:80
  },
  {
    prop:'name',label:'姓名'
  },
  {
    prop:'salary',label:'工资'
  },
  {
    prop:'job',label:'岗位'
  }]);
const insert = () =>{
  /*alert('添加成功');*/
  userData.value.push(user.value);
  user.value = {
    name:'',
    salary:'',
    job:''
  }
}
const userData = ref([
  {name:'强子',
    salary:'2500',
    job:'搬砖工人'},
])

</script>

<style scoped>

</style>